$().ready( function() {
	// 验证消息
	if($.validator != null) {
		$.extend($.validator.messages, {
		    required: "必填",
			email: "E-mail格式错误",
			url: "网址格式错误",
			date: "日期格式错误",
			dateISO: "日期格式错误",
			pointcard: "信用卡格式错误",
			number: "只允许输入数字",
			digits: "只允许输入零或正整数",
			minlength: $.validator.format("长度不允许小于{0}"),
			maxlength: $.validator.format("长度不允许大于{0}"),
			rangelength: $.validator.format("长度必须在{0}-{1}之间"),
			min: $.validator.format("不允许小于{0}"),
			max: $.validator.format("不允许大于{0}"),
			range: $.validator.format("必须在{0}-{1}之间"),
			accept: "输入后缀错误",
			equalTo: "两次输入不一致",
			remote: "输入错误",
			integer: "只允许输入整数",
			positive: "只允许输入正数",
			negative: "只允许输入负数",
			decimal: "数值超出了允许范围",
			pattern: "格式错误",
			extension: "文件格式错误"
		});
		
		$.validator.setDefaults({
			errorElement: 'div',
            errorClass: 'help-block col-md-offset-0 col-sm-offset-0 col-xs-8',
            focusInvalid: false,
			//errorClass: "fieldError",
			ignore: ".ignore",
			ignoreTitle: true,
			/**errorPlacement: function(error, element) {
				var fieldSet = element.closest("span.fieldSet");
				if (fieldSet.size() > 0) {
					error.appendTo(fieldSet);
				} else {
					error.insertAfter(element);
				}
			},**/
			highlight: function (e) {
                $(e).closest('.form-group').removeClass('has-info') .addClass('has-error');
            },
            success: function (e) {
                $(e) .closest( '.form-group') .removeClass('has-error');
                $(e).remove();
            },
            errorPlacement: function ( error, element) {
            	var elementCopy = $.extend(true,{},element);
            	var pElem = element.parent();
            	if(pElem.is("td")){
            		pElem.html(elementCopy);
            		error.insertAfter(elementCopy)
            			.removeClass("col-md-offset-0 col-sm-offset-0 col-xs-8")
            			.addClass("error");
            		elementCopy.focus();
            		return false;
				}
                if (element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                    var controls = element .closest('div[class*="col-"]');
                    if (controls.find(':checkbox,:radio').length > 1)
                        controls.append(error);
                    else
                        error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                } else if (element.is('.select2')) {
                    error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                } else if (element.is('.chosen-select')) {
                    error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                } else if (element.is('.selo2')) {
                    error.insertAfter(element.parent().parent());
                } else if (element.is('.data-select')) { //下拉框错误提示位置
                	error.insertAfter(element);
                } else
                    error.insertAfter(element.parent());
            },
            submitHandler: function (form) {},
            invalidHandler: function (form) {}
			/**
			 * 默认非form提交，如果form提交，手动$form.submit()。
			 * submitHandler: function(form) {
				$(form).find(":submit").prop("disabled", true);
				form.submit();
			}**/
		});
	}

});